<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>登陆</title>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<link href='<%=request.getContextPath() %>/static/css/style.css' type="text/css" rel="stylesheet">
		<script type="text/javascript">
			$(function () {
				$("#login_button").click(function (){
					
					var admin = new Object();
					admin.adminName = $("#admin_name").val();
					admin.adminPwd = $("#admin_pwd").val();
					if(admin.adminName == ""){
						alert("用户名不为空");
					}else if(admin.adminPwd == ""){
						alert("密码不为空");
					}else{
						jQuery.ajax({
							async : true,
							data : JSON.stringify(admin),
							dataType : "json",
							contentType:"application/json;charset=utf-8",
							success : function (result) {
							
							 var obj = JSON.parse(result);
								 if(obj.code){
									window.location.href = "http://localhost:8080/foodie/admin_login/index";//登录成功后，跳转到主页
								}else{
									alert(obj.data);
								}  	
							},
							type : "POST",
							url : "http://localhost:8080/foodie/admin_login/login"
						}); 
					};
				});
			})
		</script>
</head>

<body>
<c:set var="ctx" value="${pageContext.request.contextPath}" ></c:set>
<c:out value="${ctx }"></c:out>
	<h2 align="center">用户登陆</h2>
	
		<table border="0" align="center">
			<tr>
				<th>用户名</th>
				<td><input type="text" name="admin_name" id="admin_name" /></td>
			</tr>
			<tr>
				<th>密码</th>
				<td><input type="password" name="admin_pwd" id = "admin_pwd" /></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><button id="login_button">登录</button></td>
			</tr>
		</table>

</body>
</html>
